//
//  WorldDetailTableViewCell.m
//  MemoryTravel
//
//  Created by dllo on 15/12/24.
//  Copyright © 2015年 fcx. All rights reserved.
//

#import "WorldDetailTableViewCell.h"

@implementation WorldDetailTableViewCell



-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self creatSubviews];
        
        
    }
    return self;
}

-(void)creatSubviews
{
    self.backgroundImageView = [[UIImageView alloc]init];
    self.backgroundImageView.userInteractionEnabled = YES;
    [self.contentView addSubview:self.backgroundImageView];
    [self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(5);
        make.top.mas_equalTo(5);
        make.size.mas_equalTo(CGSizeMake(Width - 10, 260));
        
    }];
    
    self.image_urlImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"photo.jpg"]];
    self.image_urlImageView.userInteractionEnabled = YES;
    [self.backgroundImageView addSubview:self.image_urlImageView];
    [self.image_urlImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.top.mas_equalTo(0);
        make.width.equalTo(self.backgroundImageView.mas_width);
        make.height.equalTo(self.backgroundImageView.mas_height).offset(-50);
    }];
    
    self.name_zh_cnLabel = [[UILabel alloc]init];
    self.name_zh_cnLabel.text = @"日本概况";
    self.name_zh_cnLabel.textColor = [UIColor whiteColor];
    self.name_zh_cnLabel.font = [UIFont boldSystemFontOfSize:20];
    self.name_zh_cnLabel.numberOfLines = 0;
    
    [self.contentView addSubview:self.name_zh_cnLabel];
    [self.name_zh_cnLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.image_urlImageView.mas_top).offset(5);
        make.left.equalTo(self.image_urlImageView.mas_left).offset(15);
        make.size.mas_equalTo(CGSizeMake(Width - 20, 30));
        
        
    }];
    
    
    self.name_enLabel = [[UILabel alloc]init];
    self.name_enLabel.textColor = [UIColor whiteColor];
    self.name_enLabel.text = @"JAPAN";
    self.name_enLabel.font = [UIFont systemFontOfSize:13];
    
    [self.contentView addSubview:self.name_enLabel];
    [self.name_enLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.name_zh_cnLabel.mas_top).offset(20);
        make.left.equalTo(self.image_urlImageView.mas_left).offset(15);
        make.size.mas_equalTo(CGSizeMake(Width - 20, 20));
        
    }];
    
    self.lineButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.lineButton setImage:[UIImage imageNamed:@"DestinationMenuIcon2@3x.png"] forState:UIControlStateNormal];
    self.lineButton.tag = 1001;
    [self.contentView addSubview:self.lineButton];
    [self.lineButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo((Width - 75) / 4);
        make.top.equalTo(self.image_urlImageView.mas_bottom).offset(20);
        make.size.mas_equalTo(CGSizeMake(50, 50));
        
    }];
    [self.lineButton addTarget:self action:@selector(lineButtonAction:) forControlEvents:UIControlEventTouchUpInside];

    
    
    
    
    self.lineLabel = [[UILabel alloc]init];
    self.lineLabel.text = @"行程";
    [self.lineLabel sizeToFit];
    self.lineLabel.font = [UIFont systemFontOfSize:13];
    self.lineLabel.textAlignment = NSTextAlignmentCenter;
    self.lineLabel.textColor = [UIColor darkGrayColor];
    
    [self.contentView addSubview:self.lineLabel];
    [self.lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.lineButton.mas_top).offset(40);
        make.left.equalTo(self.lineButton.mas_left);
        make.size.mas_equalTo(CGSizeMake(50, 20));
        
    }];
    
    self.placeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.placeButton.tag = 1002;
    [self.backgroundImageView addSubview:self.placeButton];
    [self.placeButton setImage:[UIImage imageNamed:@"DestinationMenuIcon3@3x.png"] forState:UIControlStateNormal];

    [self.contentView addSubview:self.placeButton];
    [self.placeButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo((Width - 75) / 2);
        make.top.equalTo(self.image_urlImageView.mas_bottom).offset(20);
        make.size.mas_equalTo(CGSizeMake(50, 50));
        
        
    }];
    
    [self.placeButton addTarget:self action:@selector(placeButtonAction:) forControlEvents:UIControlEventTouchUpInside];

    
    
    self.placeLabel = [[UILabel alloc]init];
    self.placeLabel.text = @"专题";
    self.placeLabel.font = [UIFont systemFontOfSize:13];
    self.placeLabel.textAlignment = NSTextAlignmentCenter;
    [self.placeLabel sizeToFit];
    self.placeLabel.textColor = [UIColor darkGrayColor];
    [self.contentView addSubview:self.placeLabel];
    [self.placeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.placeButton.mas_left).offset(0);
        make.top.equalTo(self.placeButton.mas_top).offset(40);
        make.size.mas_equalTo(CGSizeMake(50, 20));
        
    }];
    
    self.zhuantiButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.zhuantiButton setImage:[UIImage imageNamed:@"DestinationMenuIcon1@3x.png"] forState:UIControlStateNormal];
    [self.contentView addSubview:self.zhuantiButton];
    self.zhuantiButton.tag = 1003;
    
    [self.zhuantiButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.placeButton.mas_left).offset(75);
        make.top.equalTo(self.image_urlImageView.mas_bottom).offset(20);
        make.size.mas_equalTo(CGSizeMake(50, 50));
        
    }];
    [self.zhuantiButton addTarget:self action:@selector(zhuantiButtonAction:) forControlEvents:UIControlEventTouchUpInside];

    
    
    self.zhuantiLabel = [[UILabel alloc]init];
    self.zhuantiLabel.text = @"目的地";
    self.zhuantiLabel.font = [UIFont systemFontOfSize:13];
    self.zhuantiLabel.textAlignment = NSTextAlignmentCenter;
    [self.zhuantiLabel sizeToFit];
    self.zhuantiLabel.textColor = [UIColor darkGrayColor];

    [self.contentView addSubview:self.zhuantiLabel];
    [self.zhuantiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.zhuantiButton);
        make.top.equalTo(self.zhuantiButton.mas_top).offset(40);
        make.size.mas_equalTo(CGSizeMake(50, 20));

        
        
    }];
    
    
}



- (void)lineButtonAction:(UIButton *)button
{
    NSLog(@"++++");
    // 点击按钮,触发协议方法(传值: tag, nameId, name)
    [self.delegete pushToViewControllerTag:button.tag NameId:self.aModel.nameId name:self.aModel.name_zh_cn];
}

- (void)placeButtonAction:(UIButton *)button
{
    NSLog(@"++++");
    // 点击按钮,触发协议方法(传值: tag, nameId, name)
    [self.delegete pushToViewControllerTag:button.tag NameId:self.aModel.nameId name:self.aModel.name_zh_cn];
}

- (void)zhuantiButtonAction:(UIButton *)button
{
    NSLog(@"++++");
    // 点击按钮,触发协议方法(传值: tag, nameId, name)
    [self.delegete pushToViewControllerTag:button.tag NameId:self.aModel.nameId name:self.aModel.name_zh_cn];
}



-(void)setAModel:(WorldModel *)aModel
{
    
    if (_aModel != aModel) {
        
        _aModel = aModel;
        
    }
    
    [self.image_urlImageView sd_setImageWithURL:[NSURL URLWithString:self.aModel.image_url] placeholderImage:[UIImage imageNamed:@"loading.jpg"]];
    self.name_zh_cnLabel.text = self.aModel.name_zh_cn;
    self.name_enLabel.text = self.aModel.name_en;
    
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
